home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 007a / 899track.zip / 899EDIT.PRO < prev    next >
Text File  |  1990-03-06  |  19KB  |  424 lines

  1. project "899"
  2. include "899glob.pro"
  3.  
  4. /* This file is interface to the main edit window (#100) and is
  5.    an attempt to standardize the editing procedure of descriptions  */
  6. % GLOBAL PREDICATES IN THIS FILE::
  7. %        edit_setup
  8. %        edit_descr
  9. %        edit_retrieve
  10. %        edit_setdown
  11. % IMPORTANT -- REQUIRES that window #100 already has been created somewhere
  12. %              else by the main caller.
  13.  
  14.  
  15. DATABASE - edit_def
  16.   determ window_contents(gsList)  % Hold all the strings in the window
  17.   window_line(INTEGER,gs) %  X Locatation(String Number) [Y assumed 0] and the string located there
  18.   determ window_def(INTEGER,INTEGER,INTEGER,INTEGER) % Window Max Diplayable Row and Max Diplayable Column and Attribute/Inverse
  19.   determ curr_str(INTEGER) % Current working string number)
  20.  
  21. PREDICATES
  22.   enumerate(gsList,INTEGER) % Numbers the list of strings starting at INT to whatever
  23.   renum(INTEGER,INTEGER)     % renumbers the window_lines given Starting Number and Addition Adjustment (+-1)
  24.   redef(INTEGER,INTEGER)     % used bu renum for partial sorting of window_lines
  25.   reint_normal(INTEGER,INTEGER,INTEGER)
  26.   reint_reverse(INTEGER,INTEGER,INTEGER)
  27.   rebuild_contents           % after some king of funtion this rebuilds
  28.   display_str(INTEGER,INTEGER) % display from First X position starting with String Y
  29.   d_str(INTEGER,INTEGER,INTEGER)
  30.   key_dispatch(key,INTEGER,INTEGER,INTEGER)
  31.   scr_dispatch(key,INTEGER,INTEGER,INTEGER)
  32.   cursor_check(INTEGER,INTEGER) % Check's the cursor
  33.   insert_line(INTEGER)
  34.   delete_line(INTEGER)
  35.   get_c_spec(INTEGER,gs,INTEGER)  % Returns specs of the current thing
  36.   rem_c_spec(INTEGER,gs,INTEGER)  % Returns data of current and removes it
  37.   get_max_def(INTEGER)            % Returns the number of the max
  38.   line_sort
  39.   
  40.  
  41. CLAUSES
  42.   edit_descr :-  % The call to this assumes that edit_setup has already been called
  43.     makewindow(OldWindow,_,_,_,_,_,_,_),  % Save old window
  44.     shiftwindow(100),  % Just make sure we are in this window
  45.     getbacktrack(Btop), % get this for we are doing much nondeterminism from here on
  46.     repeat,
  47.         getkey(Press,[cr, esc, del, bdel, end, home, up, down, left, right,
  48.          pgup, pgdn, ctrl_bdel,  num(0), num(1), num(2), num(3), num(4), num(5),
  49.          num(6), num(7), num(8), num(9), char('A'), char('B'), char('C'),
  50.          char('D'), char('E'), char('F'), char('G'), char('H'), char('I'),
  51.          char('J'), char('K'), char('L'), char('M'), char('N'), char('O'),
  52.          char('P'), char('Q'), char('R'), char('S'), char('T'), char('U'),
  53.          char('V'), char('W'), char('X'), char('Y'), char('Z'), char('a'),
  54.          char('b'), char('c'), char('d'), char('e'), char('f'), char('g'),
  55.          char('h'), char('i'), char('j'), char('k'), char('l'), char('m'),
  56.          char('n'), char('o'), char('p'), char('q'), char('r'), char('s'),
  57.          char('t'), char('u'), char('v'), char('w'), char('x'), char('y'),
  58.          char('z'), char('!'), char('@'), char('#'), char('$'), char('%'),
  59.          char('^'), char('&'), char('*'), char('('), char(')'), char('-'),
  60.          char('_'), char('='), char('+'), char('\\'),char('|'), char('['),
  61.          char('{'), char(']'), char('}'), char(';'), char(':'), char(','),
  62.          char('<'), char('.'), char('>'), char('/'), char('?'), char('`'),
  63.          char('~'), char('"'), char('''), char(' ')]), % get a keypress
  64.         curr_str(StrNumber),  % get the string number we are on top of
  65.         cursor(CurrX,CurrY), % get our current cursor locations
  66.         getbacktrack(Ktop),
  67.           key_dispatch(Press,CurrX,CurrY,StrNumber),
  68.         cutbacktrack(Ktop),
  69.         getbacktrack(Stop),
  70.           scr_dispatch(Press,CurrX,CurrY,StrNumber),
  71.         cutbacktrack(Stop),
  72.     Press = esc,
  73.     line_sort,
  74.     rebuild_contents,
  75.     cutbacktrack(Btop),
  76.     shiftwindow(OldWindow).
  77.  
  78.  
  79.   display_str(StartX,StringNumber) :-
  80.     cursor(OldX,OldY), % Get the old
  81.     cursor(StartX,0),  % set new
  82.     window_def(MaxX,_,_,_),
  83.     getbacktrack(Btop),
  84.     d_str(StartX,MaxX,StringNumber),
  85.     cutbacktrack(Btop),
  86.     cursor(OldX,OldY).
  87.  
  88.   d_str(MaxX,MaxX,StrNum) :-  % A terminate when we reached maximum row number
  89.     window_line(StrNum,StringToPrint), !,
  90.     writef("%-77",StringToPrint).
  91.   d_str(CurrX,MaxX,StNum) :-
  92.     window_line(StNum,StringToPrint), !,  % This may fail if to far past
  93.     writef("%-77",StringToPrint), NextX = CurrX + 1,  NextStr = StNum + 1,
  94.     cursor(NextX,0),
  95.     d_str(NextX,MaxX,NextStr).
  96.   d_str(_,_,_).
  97.  
  98.  
  99.   edit_setup(ListOfStrings,Title) :-
  100.     assert(window_contents(ListOfStrings),edit_def),  % Add this to our current definition
  101.     assert(curr_str(0),edit_def),
  102.     makewindow(CurrW,_,_,_,_,_,_,_),                  % Get the current Window to save
  103.     shiftwindow(100),                                 % Move to our window
  104.     change_window_title(Title),
  105.     makewindow(_,Attribute,_,_,_,_,Wrsize,Wcsize),    % Get OUR window's thing
  106.     cursor(0,0),
  107.     UsableRows = Wrsize - 3,                          % Calculate usable rows
  108.     UsableColumns = Wcsize - 3,                       % calculate usable columns
  109.     inverse(Attribute,InvAttribute),                  % calcluate the inverse attribute
  110.     assert(window_def(UsableRows,UsableColumns,Attribute,InvAttribute),edit_def),
  111.     enumerate(ListOfStrings,0),                       % and enumerate the given list of strings
  112.     getbacktrack(Btop),
  113.       display_str(0,0),
  114.     cutbacktrack(Btop),
  115.     cursor(0,0),
  116.     shiftwindow(CurrW).
  117.     
  118.   enumerate([],LastNumber) :- !,  % Terminating condition
  119.     assert(window_line(LastNumber,terminate),edit_def).
  120.   enumerate([Astring|RestOfList],StringNumber) :-
  121.     assert(window_line(StringNumber,Astring),edit_def), % Place a string in memory
  122.     NextNumber = StringNumber+1,
  123.     enumerate(RestOfList,NextNumber).
  124.  
  125.   edit_retrieve(ListOfStrings) :- % Return our list of strings -- non destrictive
  126.     window_contents(ListOfStrings).
  127.  
  128.   edit_setdown(ListOfStrings) :-
  129.     retract(window_contents(ListOfStrings),edit_def),
  130.     retractall(_,edit_def),
  131.     makewindow(CurrW,_,_,_,_,_,_,_),                  % Get the current Window to save
  132.     shiftwindow(100),                                 % Move to our window 
  133.     clearwindow,
  134.     change_window_title(edit_title),
  135.     shiftwindow(CurrW).
  136.  
  137.   rebuild_contents :-
  138.    retract(window_contents(_),edit_def),
  139.    findall(Data,window_line(_,Data),NewList),
  140.    expgsList(terminate,NewList,ExtraNewList),  % Take the terminator out
  141.    assert(window_contents(ExtraNewList),edit_def).
  142.  
  143.  
  144.   renum(StartingNumber,AdjustmentFactor) :- % POSITIVE ADJUSTMENT nonzero
  145.     AdjustmentFactor > 0,   % This clause is for positive adjustment thuss adding a line
  146.     StartingNumber <> 0, !,
  147.     window_line(LastNumber,terminate),  % Grab the last line number which will terminate this thing
  148.     BreakingPoint = StartingNumber - 1, % for renumbering
  149.     redef(0,BreakingPoint),             % redefine for sorting the numbers
  150.     reint_reverse(StartingNumber,LastNumber,AdjustmentFactor),
  151.     asserta(window_line(StartingNumber,""),edit_def),
  152.     NewLastNumber = LastNumber + AdjustmentFactor,
  153.     redef(StartingNumber,NewLastNumber). % and thus the information is sorted
  154.   renum(StartingNumber,AdjustmentFactor) :- % POSITIVE ADJUSTMENT ZERO!!
  155.     AdjustmentFactor > 0, !,  % This clause is for positive adjustment thuss adding a line
  156.     window_line(LastNumber,terminate),  % Grab the last line number which will terminate this thing
  157.     reint_reverse(StartingNumber,LastNumber,AdjustmentFactor),
  158.     asserta(window_line(StartingNumber,""),edit_def),
  159.     NewLastNumber = LastNumber + AdjustmentFactor,
  160.     redef(StartingNumber,NewLastNumber). % and thus the information is sorted
  161.   renum(StartingNumber,AdjustmentFactor) :- % NEGATIVE ADJUSTMENT
  162.     window_line(LastNumber,terminate),
  163.     retract(window_line(StartingNumber,_),edit_def),  % Take it out
  164.     NewS = StartingNumber + 1,
  165.     reint_normal(NewS,LastNumber,AdjustmentFactor), % adjust all above
  166.     NewLastNumber = LastNumber + AdjustMentfactor,
  167.     redef(0,NewLastNumber). % Sort it.
  168.     
  169.  
  170.   reint_reverse(StartingNumber,StartingNumber,Adj) :- !, % Stopping
  171.     retract(window_line(StartingNumber,Data),edit_def),
  172.     NewNum = StartingNumber + Adj,
  173.     asserta(window_line(NewNum,Data),edit_def).
  174.   reint_reverse(EndingNumber,CurrNum,Adj) :-
  175.     retract(window_line(CurrNum,Data),edit_def),
  176.     NewNum = CurrNum + Adj,
  177.     asserta(window_line(NewNum,Data),edit_def),
  178.     NextElement = CurrNum - Adj,
  179.     reint_reverse(EndingNumber,NextElement,Adj).
  180.  
  181.   reint_normal(LastNumber,LastNumber,Adj) :- !,
  182.     retract(window_line(LastNumber,Data),edit_def),
  183.     NewNum = LastNumber + Adj,
  184.     asserta(window_line(NewNum,Data),edit_def).
  185.   reint_normal(CurrNum,LastNum,Adj) :-
  186.     retract(window_line(CurrNum,Data),edit_def),
  187.     NewNum = CurrNum + Adj,
  188.     asserta(window_line(NewNum,Data),edit_def),
  189.     NextElement = CurrNum - Adj,
  190.     reint_normal(NextElement,LastNum,Adj).
  191.     
  192.   redef(BreakingPoint,BreakingPoint) :-  !, % Last one to put back
  193.     retract(window_line(BreakingPoint,Data),edit_def),
  194.     assertz(window_line(BreakingPoint,Data),edit_def).
  195.   redef(CurrLine,BreakingPoint) :-
  196.     retract(window_line(CurrLine,Data),edit_def),
  197.     assertz(window_line(CurrLine,Data),edit_def),
  198.     NextLine = CurrLine + 1,
  199.     redef(NextLine,BreakingPoint).
  200.  
  201.   key_dispatch(esc,_,_,_) :- !.          % The terminating condition
  202.   key_dispatch(cr,_,CurrY,Cstr) :-
  203.     get_max_def(MaxDef),
  204.     Cstr < MaxDef, !,
  205.     insert_line(Cstr),                   /* Do this */
  206.     NextLine = Cstr + 1,
  207.     rem_c_spec(NextLine,Data,_),            % Remove current information
  208.     frontstr(CurrY,Data,StuffToLeave,StuffToGo),  % Split the string
  209.     rem_c_spec(Cstr,_,_),
  210.     assert(window_line(Cstr,StuffToLeave),edit_def),
  211.     assert(window_line(NextLine,StuffToGo),edit_def),
  212.     line_sort.    % Sort
  213.   key_dispatch(ctrl_bdel,_,_,CstrNum) :-
  214.     get_max_def(MaxStrN),
  215.     CstrNum < MaxStrN, !,
  216.     delete_line(CstrNum).
  217.   key_dispatch(char(C),_,0,StrNum) :-    % This is for the beginning of the string
  218.     get_max_def(MaxDef),
  219.     StrNum < MaxDef,                     % So we don't edit the terminator
  220.     get_c_spec(StrNum,_,DataLen),
  221.     window_def(_,MaxY,_,_),
  222.     DataLen < (MaxY-1), !,                   % So we cant go past the end
  223.     rem_c_spec(StrNum,Data,_),
  224.     str_char(Stc,C),
  225.     concat(Stc,Data,NewString),          % Append the char to the front
  226.     assert(window_line(StrNum,NewString),edit_def),
  227.     line_sort.                     % Resort the items
  228.   key_dispatch(char(C),_,CurrY,StrNum) :- % Here may be in middle or at end
  229.     get_max_def(MaxN),
  230.     StrNum < MaxN,                       % So we don't edit terminator
  231.     get_c_spec(StrNum,Xdata,ItsLength),
  232.     window_def(_,MaxY,_,_),
  233.     ItsLength < (MaxY-1),                    % So we don't go past the end
  234.     CurrY >= ItsLength, !,               % From here on out, the cursor is at the end of the line
  235.     rem_c_spec(StrNum,_,_),              % Take it out
  236.     str_char(CharToS,C),                 % Convert Char to string
  237.     concat(Xdata,ChartoS,NewData),       % Make the new string
  238.     assert(window_line(StrNum,NewData),edit_def),
  239.     line_sort.  % Resort
  240.   key_dispatch(char(C),_,CurrY,StrNum) :- !, /* Here, the cursor is in the middle of the string */
  241.     get_max_def(MaxDef),
  242.     StrNum < MaxDef,                     % So we don't edit terminator
  243.     get_c_spec(StrNum,_,DataLen),
  244.     window_def(_,MaxY,_,_),             % so we dont' go past end
  245.     DataLen < (MaxY-1),  !,
  246.     rem_c_spec(StrNum,Xdata,_),          % take it out
  247.     frontstr(CurrY,Xdata,LeftOfCursor,RightOfCursor),
  248.     str_char(Cs,C),                      % convert to char
  249.     concat(LeftOfCursor,Cs,NewLeftOfCursor),
  250.     concat(NewLeftOfCursor,RightOfCursor,NewString),
  251.     assert(window_line(StrNum,NewString),edit_def),
  252.     line_sort.                     % sort
  253.   key_dispatch(bdel,_,CurrY,StrNum) :-   % Backspace Key hit
  254.     CurrY > 0, 
  255.     get_max_def(MaxDef),
  256.     StrNum < MaxDef,   !,
  257.     rem_c_spec(StrNum,Data,_), % Take the string
  258.     PosToDel = CurrY - 1,  % The char to delete is here!
  259.     frontstr(PosToDel,Data,LeftHalf,RightHalf),
  260.     frontchar(RightHalf,_,NewRightHalf),  % Delete the front on second
  261.     concat(LeftHalf,NewRightHalf,NewData),
  262.     assert(window_line(StrNum,NewData),edit_def),
  263.     line_sort. % Resort
  264.   key_dispatch(del,_,CurrY,StrNum) :-    % DEl Key
  265.     get_max_def(MaxDef),
  266.     StrNum < MaxDef,
  267.     get_c_spec(StrNum,Data,DataLen),
  268.     CurrY < DataLen, !,                  % conditionary clause
  269.     rem_c_spec(StrNum,_,_),
  270.     frontstr(CurrY,Data,LeftHalf,RightHalf),
  271.     frontchar(RightHalf,_,NewRightHalf), % Delete the front on second
  272.     concat(LeftHalf,NewRightHalf,NewData),
  273.     assert(window_line(StrNum,NewData),edit_def),
  274.     line_sort.                     % Resort
  275.   key_dispatch(num(N),CurrX,CurrY,StrNum) :- !,
  276.     Cn = N + $30,
  277.     char_int(Car,Cn),
  278.     key_dispatch(char(Car),CurrX,CurrY,StrNum).
  279.   key_dispatch(up,_,_,CurrStringNumber) :-
  280.     NewStNum = CurrStringNumber - 1,
  281.     window_line(NewStNum,_), !,          % If a definition exists
  282.     retract(curr_str(CurrStringNumber),edit_def),
  283.     assert(curr_str(NewStNum),edit_def).
  284.   key_dispatch(down,_,_,CstrNum) :-
  285.     NewStNum = CstrNum + 1,
  286.     window_line(NewStNum,_), !,          % If the next line exists
  287.     retract(curr_str(CstrNum),edit_def),
  288.     assert(curr_str(NewStNum),edit_def).
  289.   key_dispatch(_,_,_,_).
  290.  
  291.  
  292.   scr_dispatch(esc,_,_,_) :- !.          % The termiateing condition
  293.   scr_dispatch(cr,CurrX,_,Cstr) :-
  294.     FirstElem = Cstr - CurrX,
  295.     display_str(0,FirstElem),            % Redisplay
  296.     window_def(MaxX,_,_,_),
  297.     CurrX = MaxX, !,
  298.     NewD = Cstr + 1,
  299.     StartStr = NewD - MaxX,
  300.     display_str(0,StartStr),
  301.     cursor_check(MaxX,0).
  302.   scr_dispatch(cr,CurrX,_,Cstr) :-
  303.     !, NewX = CurrX + 1,
  304.     cursor(NewX,0),
  305.     retract(curr_str(_),edit_def),
  306.     NewStr = Cstr + 1,
  307.     assert(curr_str(NewStr),edit_def).
  308.   scr_dispatch(ctrl_bdel,CurrX,_,CtrnNum) :- !,
  309.     FirstElem = CtrnNum - CurrX,
  310.     clearwindow,
  311.     display_str(0,FirstElem),
  312.     cursor(CurrX,0).
  313.   scr_dispatch(char(_),CurrX,CurrY,StrNum) :-  % the same for all chars
  314.     get_max_def(MaxDef),
  315.     StrNum < MaxDef,
  316.     get_c_spec(StrNum,Data,DataLen),           % Grab the new line
  317.     window_def(_,MaxY,_,_),
  318.     DataLen < MaxY, !,
  319.     cursor(CurrX,0), writef("%-77",Data),
  320.     NewY = CurrY + 1,
  321.     cursor(CurrX,NewY).
  322.   scr_dispatch(bdel,CurrX,CurrY,StrNum) :-
  323.     CurrY > 0,
  324.     get_max_def(MaxDef),
  325.     StrNum < MaxDef,    !,
  326.     get_c_spec(StrNum,Data,_),
  327.     cursor(CurrX,0), writef("%-77",Data),
  328.     NewY = CurrY - 1,
  329.     cursor(CurrX,NewY).
  330.   scr_dispatch(del,CurrX,CurrY,StrNum) :-
  331.     get_max_def(MaxDef),
  332.     StrNum < MaxDef, !,
  333.     get_c_spec(StrNum,Data,_),
  334.     cursor(CurrX,0), writef("%-77",Data),
  335.     cursor(CurrX,CurrY).
  336.   scr_dispatch(num(N),CurrX,CurrY,StrNum) :- !,
  337.     Cn = N + $30,
  338.     char_int(Car,Cn),
  339.     scr_dispatch(char(Car),CurrX,CurrY,StrNum).
  340.   scr_dispatch(home,CurrX,_,_) :-
  341.     !, cursor(CurrX,0).
  342.   scr_dispatch(end,CurrX,_,StrNum) :-
  343.     !, get_c_spec(StrNum,_,NewY), cursor(CurrX,NewY).
  344.   scr_dispatch(up,0,CurrY,StrNum) :-
  345.     curr_str(ActualC),                   % Grab the actual current string number
  346.     ActualC <> StrNum, !,                % If they are the same, then key_dispatch clause failed
  347.     % At this point the entire window must be refreshed!!
  348.     scroll(-1,0),                        % scrol the screen
  349.     window_line(ActualC,Stp),
  350.     cursor(0,0),
  351.     writef("%-77",Stp),
  352.     cursor_check(0,CurrY).
  353.   scr_dispatch(up,CurrX,CurrY,StrNum) :- % here, there are 2 ways the above may have failed
  354.     curr_str(ActualC),                   % Grab the actual current string number
  355.     ActualC <> StrNum, !,                % If they are the same, then key_dispatch clause failed and above failed
  356.     NewX = CurrX - 1,                    % Thus simply move the cursor up one
  357.     cursor_check(NewX,CurrY).
  358.   scr_dispatch(down,CurrX,CurrY,StrNum) :-
  359.     curr_str(ActualC),
  360.     ActualC <> StrNum,                   % Meaning that there is another displayable string
  361.     window_def(MaxRow,_,_,_),
  362.     CurrX = MaxRow, !,                   % Means that the window must be refreshed
  363.     scroll(1,0),
  364.     window_line(ActualC,Stp),
  365.     cursor(MaxRow,0),
  366.     writef("%-77",Stp),
  367.     cursor_check(CurrX,CurrY).
  368.   scr_dispatch(down,CurrX,CurrY,StrNum) :-
  369.     curr_str(ActualC),
  370.     ActualC <> StrNum,!,                 % Meaning that there is another displayable string
  371.     NextRow = CurrX + 1,
  372.     cursor_check(NextRow,CurrY).
  373.   scr_dispatch(left,CurrX,CurrY,_) :-
  374.     NewY = CurrY - 1,
  375.     NewY >= 0, !,
  376.     cursor(CurrX,NewY).
  377.   scr_dispatch(right,CurrX,CurrY,StrNum) :-
  378.     window_line(StrNum,Str),
  379.     str_len(Str,MaxY),
  380.     NewY = CurrY + 1,
  381.     NewY <= MaxY, !,
  382.     cursor(CurrX,NewY).
  383.   scr_dispatch(_,_,_,_).
  384.  
  385.  
  386.   cursor_check(CurrX,CurrY) :-
  387.     curr_str(CurrNum), window_line(CurrNum,Str), str_len(Str,MaxY),
  388.     CurrY > MaxY, !,  % If the newy is bigger than line max, then adjust
  389.     cursor(CurrX,MaxY).
  390.   cursor_check(X,Y) :-
  391.     cursor(X,Y).   % Otherwise, it's fine
  392.  
  393.   insert_line(CurrentStringNumber) :-
  394.     /* This inserts an empty string before the current string so that
  395.        upon exit, the CurrentStringNumber is the number of "" and
  396.        the old String number is one greater */
  397.     renum(CurrentStringNumber,1).  /* Readgust all the numbers by one */
  398.  
  399.   delete_line(CurrentStringNumber) :-
  400.     /* This delete the current string number line so that upon exit,
  401.        the base will have one less string  */
  402.     renum(CurrentStringNumber,-1). /* Readjust internally */
  403.  
  404.   get_c_spec(StrNum,Data,DataLen) :-
  405.     getbacktrack(Btop),
  406.     window_line(StrNum,Data),
  407.     str_len(Data,DataLen),
  408.     cutbacktrack(Btop).
  409.  
  410.   rem_c_spec(StrNum,Data,DataLen) :-
  411.     getbacktrack(Btop),
  412.     get_c_spec(StrNum,Data,DataLen),
  413.     retract(window_line(StrNum,_),edit_def),
  414.     cutbacktrack(Btop).
  415.  
  416.   get_max_def(MaxNum) :-
  417.     getbacktrack(Btop),
  418.     window_line(MaxNum,terminate),
  419.     cutbacktrack(Btop).
  420.  
  421.   line_sort :-
  422.     window_line(MaxDef,terminate),  % Grab the terminate
  423.     redef(0,MaxDef).
  424.